#!/usr/bin/env node
import { program } from "commander";
import { PackManager } from "./pack/PackManager";
let i = 2;
let projectDir = "";
let channel = "";
let isdebug = false;
let version: string | null = null!;
let desc: string = "";
let androidBundle: boolean = false;
let bmsname: string = "";
let bmsversion: string = "";
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = '1';
program
    .option("-p, --path <value>", "Cocos项目根目录[Path]")
    .option("-c, --channel <value>", "指定打包对应渠道名称[ChannelName]")
    .option("-v, --version <value>", "设置打包的版本号格式x.x.x")
    .option("-d, --debug", "是否为测试包true:不是测试包,false:测试包", false)
    .option("-b, --bundle", "是否打包App Bundle 安卓需要 [value]=true|false", false)
    .option("-s, --skip", "是否跳过cocos构建工程，直接使用导出工程 [value]=true|false", false)
    .option("-no, --nonotify", "是否跳过钉钉通知")
    .option("-t, --tdesc [pp]", "小游戏后台上传描述，字节微信等", "")
    .option("-bn, --BMSName [pp]", "实名控制的BMSName", "")
    .option("-bv, --BMSVersion [pp]", "实名控制的BMSVersion", "")
    .option("-cp, --compress", "是否压缩资源", "")
    .option("-oc, --obfuscated", "是否混淆", "")
    .option("-rc, --remoteConfig [pp]", "远程配置路径", "")
    .option("-l, --local", "是否本地", "")
    .option("-mc, --config", "是否压缩配置", "")
    .option("-svn, --svnConfigPath [pp]", "配置表", "")

program.parse(process.argv);
projectDir = program.getOptionValue("path");
channel = program.getOptionValue("channel");
version = program.getOptionValue("version");
isdebug = program.getOptionValue("debug");
desc = program.getOptionValue("tdesc");
androidBundle = program.getOptionValue("bundle");
bmsname = program.getOptionValue("BMSName");
bmsversion = program.getOptionValue("BMSVersion");
const skip = program.getOptionValue("skip");
const nonotify = program.getOptionValue("nonotify");
const iscompress = program.getOptionValue("compress");
const isoc = program.getOptionValue("obfuscated");
const remoteconfig = program.getOptionValue("remoteConfig");
const islocal = program.getOptionValue("local");
const compressCfg = program.getOptionValue("config");
const svnPath = program.getOptionValue("svnConfigPath");
//@ts-ignore
global.isSkipBuild = skip;
//@ts-ignore
global.isSkipNotify = !!nonotify;
//@ts-ignore
global.isCompress = !!iscompress;
//@ts-ignore
global.isOc = !!isoc;
//@ts-ignore
global.remoteConfig = (remoteconfig && remoteconfig.length > 0) ? remoteconfig : "";
//@ts-ignore
global.isPackLocal = !!islocal;
//@ts-ignore
global.compressCfg = !!compressCfg;
if (typeof bmsversion != "boolean") {
    //@ts-ignore
    global.bmsVersion = bmsversion || "";
}
if (typeof svnPath != "boolean") {
    //@ts-ignore
    global.gameConfigPath = svnPath || "";
}
if (projectDir && channel) {
    PackManager.init(projectDir, channel, isdebug, version!, desc, androidBundle, bmsname, bmsversion);
}
/*e:
cd e:/project/auto-pack-creator/build
set batcommond=
if %ISDEBUG%==true set batcommond=-d
if %ISBUNDLE%==true set batcommond=%batcommond% -b
if %ISSKIP%==true set batcommond=%batcommond% -s
for %%i in (%PLATFORMS%) do (node ./app.js -p %WORKSPACE% -c %%i -v %VERSION% -t %UPLOAD_DESC% -bn %BMS_NAME% -bv %BMS_VERSION% %batcommond%)*/

/*
batchcommond=""
if test "$ISDEBUG" = "true"; then
    batchcommond="$batchcommond-d"
fi

if test "$ISSKIP" = "true"; then
    batchcommond="$batchcommond -s"
fi
node ./app.js -p $WORKSPACE -c $PLATFORMS -v $VERSION -bv $BMS_VERSION $batchcommond*/